﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using TravelLink.WebModel;
using TravelLink.DAL;

namespace TravelLink.WebApp.UserControl.Search {
    public partial class UC_Position_Detailv2 : ControlBase {


        TL_Company_Position position = null;

        string Empty = "&nbsp;";

        public string PositionCode {
            get {
                return this.position.PositionCode.ToString();
            }
        }

        protected void Page_Load(object sender, EventArgs e) {
            Guid positionCode = new Guid(WebHelper.GetQueryStringStr("pc", Guid.Empty.ToString()));
            var db = DataContextFactory.Create();
            position = db.TL_Company_Position.Where(u => u.PositionCode == positionCode).FirstOrDefault();
        }

        public string PositionName {
            get {
                return Output(position.PositionName);
            }
        }

        public string ReportTo {
            get {
                return Output(position.ReportTo);
            }
        }

        public string WorkIn {
            get {
                if (position.TL_City != null)
                    return Output(position.TL_City.CName);
                else {
                    return Empty;
                }
            }
        }

        public string PositionType {
            get {
                if (this.position.TL_PositionType != null) {
                    return Output(this.position.TL_PositionType.Name);
                }
                else {
                    return Empty;
                }
            }
        }

        public string PositionLevel {
            get {
                if (this.position.TL_PositionLevel != null) {
                    return Output(this.position.TL_PositionLevel.Name);
                }
                else {
                    return Empty;
                }
            }
        }


        public string PositionDescription {
            get {
                if (!string.IsNullOrEmpty(this.position.Description)) {
                    return Output(this.position.Description.Replace("\r", "<br/>"));
                }
                else {
                    return Empty;
                }
            }
        }

        public string Other {
            get {
                if (!string.IsNullOrEmpty(this.position.OtherInfo)) {
                    return Output(this.position.OtherInfo.Replace("\r", "<br/>"));
                }
                else {
                    return Empty;
                }
            }
        }


        public string Salary {
            get {
                if (!string.IsNullOrEmpty(this.position.Salary)) {
                    return Output(this.position.Salary);
                }
                else {
                    return Empty;
                }
            }
        }

        public string ContactTel {
            get {
                if (!string.IsNullOrEmpty(this.position.TL_Company.ContactTel)) {
                    return Output(this.position.TL_Company.ContactTel);
                }
                else {
                    return Empty;

                }
            }
        }

        public string PublishDate {
            get {
                return Output(this.position.PublishDate.Value.ToString("yyyy-MM-dd"));
            }
        }

        public string PeiodDate {
            get {
                return Output(this.position.PeriodTo.Value.ToString("yyyy-MM-dd"));
            }
        }

        public string CompanyName {
            get {
                return Output(this.position.TL_Company.CompanyName);
            }
        }

        public string CompanyType {
            get {
                if (this.position.TL_Company.TL_BussinessType != null) {
                    return Output(this.position.TL_Company.TL_BussinessType.Name);
                }
                return string.Empty;
            }
        }


        public string WebSite {
            get {
                if (!string.IsNullOrEmpty(this.position.TL_Company.WebSite))
                    return Output(this.position.TL_Company.WebSite);
                else
                    return
                        Empty;
            }
        }

        public string CompanyLogo {
            get {
                if (!string.IsNullOrEmpty(this.position.TL_Company.CompanyLogo))
                    return Output(string.Format("<img width='60' height='30' src='{0}' />", "/Images/Company/" + this.position.TL_Company.CompanyLogo));
                else
                    return
                        Empty;
            }
        }

        public string IndustryType {
            get {
                if (this.position.TL_Company != null && this.position.TL_Company.TL_Company_Industry != null && this.position.TL_Company.TL_Company_Industry.Count > 0) {
                    StringBuilder str = new StringBuilder();
                    foreach (var item in this.position.TL_Company.TL_Company_Industry) {
                        str.Append(item.TL_IndustryType2.TL_IndustryType1.Name + " -> " + item.TL_IndustryType2.Name).Append(",");
                    }
                    if (str.Length > 0)
                        str.Length = str.Length - 1;

                    return Output(str.ToString());
                }
                else {
                    return Empty;
                }
            }
        }

        public string CompanyDescription {
            get {
                if (!string.IsNullOrEmpty(this.position.TL_Company.CompanyBrief)) {
                    return Output(this.position.TL_Company.CompanyBrief.Replace("\r", "<br/>"));
                }
                else {
                    return Empty;
                }
            }
        }


        public string Requemnts {
            get {
                if (!string.IsNullOrEmpty(this.position.Requirement)) {
                    return Output(this.position.Requirement.Replace("\r", "<br/>"));
                }
                else {
                    return Empty;
                }
            }
        }

        public string Output(string msg) {
            if (string.IsNullOrEmpty(msg)) return string.Empty;
            return msg;
        }

    }
}